package com.aiwei.tdjk.service.impl;

import com.aiwei.tdjk.bean.Pager;
import com.aiwei.tdjk.dao.extend.BookingContainerExtendMapper;
import com.aiwei.tdjk.dto.request.BookingContainerPagerRequest;
import com.aiwei.tdjk.entity.BookingContainer;
import com.aiwei.tdjk.entity.BookingContainerExample;
import com.aiwei.tdjk.enums.BookingContainerStatusEnum;
import com.aiwei.tdjk.service.BookingContainerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookingContainerServiceImpl implements BookingContainerService{

    @Autowired
    private BookingContainerExtendMapper bookingContainerExtendMapper;


    /**
     * 分页查询
     * @param request
     * @return
     */
    @Override
    public Pager<BookingContainer> find(BookingContainerPagerRequest request) {
        request.webParamConvert();
        List<BookingContainer> list = bookingContainerExtendMapper.find(request);
        int totalCount = bookingContainerExtendMapper.getTotalCount(request);
        Pager<BookingContainer> pager = new Pager<>();
        pager.setPageNumber(request.getPageNumber());
        pager.setPageSize(request.getPageSize());
        pager.setList(list);
        pager.setTotalCount(totalCount);
        return pager;
    }


    /**
     * 获取
     * @param id
     * @return
     */
    @Override
    public BookingContainer get(Long id){
        return bookingContainerExtendMapper.selectByPrimaryKey(id);
    }

    @Override
    public BookingContainer getBySaleOrderCode(String saleOrderCode) {
        BookingContainerExample example =new BookingContainerExample();
        example.or().andSaleOrderCodeEqualTo(saleOrderCode);
        List<BookingContainer> bookingContainers = bookingContainerExtendMapper.selectByExample(example);
        if (bookingContainers!=null){
            return bookingContainers.get(0);
        }
        return null;
    }


    /**
     * 新增
     *
     * @param bookingContainer
     * @return
     */
    @Override
    public int add(BookingContainer bookingContainer) {
        return bookingContainerExtendMapper.insertSelective(bookingContainer);
    }

    /**
     * 更新
     *
     * @param bookingContainer
     */
    @Override
    public void update(BookingContainer bookingContainer) {
        bookingContainerExtendMapper.updateByPrimaryKeySelective(bookingContainer);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        BookingContainer bookingContainer = get(id);
        bookingContainer.setStatus(BookingContainerStatusEnum.deleted.getCode());
        bookingContainerExtendMapper.updateByPrimaryKeySelective(bookingContainer);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void delete(Long[] id) {

    }

}
